home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / fntool / main.c < prev    next >
Text File  |  1993-12-06  |  6KB  |  197 lines

  1. #define  EXTERN
  2. #include "fntool.h"
  3. #include <stdarg.h>
  4.  
  5. static char *progname;
  6. static char usage[] = {
  7. "usage: fntool [options] file1 file2 ...\n"
  8. "  options:\n"
  9. "    -itype {C|fna|fnt|bdf}     input file type (default: fna)\n"
  10. "    -otype {C|fna|fnt|dir}     output file type (default: fnt)\n"
  11. "    -oname <pattern>           output name or pattern.\n"
  12. "           pattern format sequences:\n"
  13. "             %W=font Width, %H=font Height,\n"
  14. "             %G=font weiGht (bold, etc..), %S=slant (italic, etc..),\n"
  15. "             %U=make font name Unique\n"
  16. "    -family <name>             font family name\n"
  17. "    -minchar <value>           lowest character code to convert\n"
  18. "    -maxchar <value>           highest character code to convert\n"
  19. "    -cvtp2f                    convert proportional to fixed\n"
  20. "    -cvtf2p                    convert fixed to proportional\n"
  21. "    -centerwidth               center characters horizontally\n"
  22. "    -centerheight              center characters vertically\n"
  23. "    -resize <width> <height>   resize font to width by height\n"
  24. "    -show                      display font before saving\n"
  25. "    -edit                      edit font before saving\n"
  26. "    -verbose                   verbose operation\n"
  27. "    -help                      show this screen\n"
  28. };
  29.  
  30. static void argerr(char *msg,...)
  31. {
  32.     va_list ap;
  33.  
  34.     va_start(ap,msg);
  35.     fprintf(stderr,"%s: ",progname);
  36.     vfprintf(stderr,msg,ap);
  37.     putc('\n',stderr);
  38.     va_end(ap);
  39.     fputs(usage,stderr);
  40.     exit(1);
  41. }
  42.  
  43. static void checkoptions(void)
  44. {
  45.     if(opt.minchar < 0)  opt.minchar = 0;
  46.     if(opt.maxchar <= 0) opt.maxchar = 32767;
  47.     if(opt.maxchar < opt.minchar) opt.maxchar = opt.minchar;
  48.     if(opt.do_resize && ((opt.res_wdt < 3) || (opt.res_hgt < 3))) {
  49.         fprintf(stderr,"%s: invalid font size (%dx%d) for \"-resize\""
  50.         " option\nWARNING: resizing not done\n",
  51.         progname,
  52.         opt.res_wdt,
  53.         opt.res_hgt
  54.         );
  55.         opt.do_resize = 0;
  56.     }
  57.     if(opt.do_fix2prop && opt.do_prop2fix) {
  58.         fprintf(stderr,"%s: both fixed to proportional and\n"
  59.         "proportional to fixed conversion specified!\n"
  60.         "WARNING: no conversion is done\n",
  61.         progname
  62.         );
  63.         opt.do_fix2prop = 0;
  64.         opt.do_prop2fix = 0;
  65.     }
  66.     if(opt.do_edit || opt.do_show) opt.verbose = 0;
  67.     if(opt.do_edit && opt.do_show) opt.do_show = 0;
  68.     switch(opt.outtype) {
  69.       case _C_:
  70.       case FNA:
  71.         break;
  72.       case DIR:
  73.         if(opt.namepattern[0] == '\0')
  74.         strcpy(opt.namepattern,"fonts.dir");
  75.         break;
  76.       default:
  77.         opt.outtype = FNT;
  78.         break;
  79.     }
  80. }
  81.  
  82. #ifdef __GNUC__
  83. static int compareargs(void *first,void *second)
  84. #endif
  85. #ifdef __TURBOC__
  86. static int compareargs(const void *first,const void *second)
  87. #endif
  88. {
  89.     return(strcmp(*((char **)first),*((char **)second)));
  90. }
  91.  
  92. void main(int argc,char **argv)
  93. {
  94.     static char noarg[]  = { "missing argument(s) for option \"%s\"" };
  95.     static char invarg[] = { "invalid argument(s) for option \"%s\"" };
  96.     char *ap;
  97.     char **inputs;
  98.     int  inputno;
  99.  
  100.     progname = *argv;
  101.     memset(&opt,0,sizeof(opt));
  102.     inputs = malloc(sizeof(char *) * argc);
  103.     inputno = 0;
  104.     while(--argc > 0) {
  105.         if(*(ap = *++argv) != '-') {
  106.         inputs[inputno] = ap;
  107.         inputno++;
  108.         continue;
  109.         }
  110.         if(strmatch(ap,"-centerh")) {
  111.         opt.do_centerhgt = 1;
  112.         continue;
  113.         }
  114.         if(strmatch(ap,"-centerw")) {
  115.         opt.do_centerwdt = 1;
  116.         continue;
  117.         }
  118.         if(strmatch(ap,"-cvtf2p")) {
  119.         opt.do_fix2prop = 1;
  120.         continue;
  121.         }
  122.         if(strmatch(ap,"-cvtp2f")) {
  123.         opt.do_prop2fix = 1;
  124.         continue;
  125.         }
  126.         if(strmatch(ap,"-ed")) {
  127.         opt.do_edit = 1;
  128.         continue;
  129.         }
  130.         if(strmatch(ap,"-fam")) {
  131.         if(--argc <= 0) argerr(noarg,"-family");
  132.         strcpy(opt.family,*++argv);
  133.         continue;
  134.         }
  135.         if(strmatch(ap,"-h")) {
  136.         printf("%s:\n%s",progname,usage);
  137.         exit(0);
  138.         }
  139.         if(strmatch(ap,"-i")) {
  140.         if(--argc <= 0) argerr(noarg,"-itype");
  141.         ap = *++argv;
  142.         if(strmatch(ap,"C"))   { opt.intype = _C_; continue; }
  143.         if(strmatch(ap,"fna")) { opt.intype = FNA; continue; }
  144.         if(strmatch(ap,"fnt")) { opt.intype = FNT; continue; }
  145.         if(strmatch(ap,"bdf")) { opt.intype = BDF; continue; }
  146.         argerr(invarg,"-itype");
  147.         }
  148.         if(strmatch(ap,"-minc")) {
  149.         if(--argc <= 0) argerr(noarg,"-minchar");
  150.         if(sscanf(*++argv,"%d",&opt.minchar) != 1) argerr(invarg,"-minchar");
  151.         continue;
  152.         }
  153.         if(strmatch(ap,"-maxc")) {
  154.         if(--argc <= 0) argerr(noarg,"-maxchar");
  155.         if(sscanf(*++argv,"%d",&opt.maxchar) != 1) argerr(invarg,"-maxchar");
  156.         continue;
  157.         }
  158.         if(strmatch(ap,"-on")) {
  159.         if(--argc <= 0) argerr(noarg,"-oname");
  160.         strcpy(opt.namepattern,*++argv);
  161.         continue;
  162.         }
  163.         if(strmatch(ap,"-ot")) {
  164.         if(--argc <= 0) argerr(noarg,"-otype");
  165.         ap = *++argv;
  166.         if(strmatch(ap,"C"))   { opt.outtype = _C_; continue; }
  167.         if(strmatch(ap,"fna")) { opt.outtype = FNA; continue; }
  168.         if(strmatch(ap,"fnt")) { opt.outtype = FNT; continue; }
  169.         if(strmatch(ap,"dir")) { opt.outtype = DIR; continue; }
  170.         argerr(invarg,"-otype");
  171.         }
  172.         if(strmatch(ap,"-res")) {
  173.         if((argc -= 2) <= 0) argerr(noarg,"-resize");
  174.         if(sscanf(*++argv,"%d",&opt.res_wdt) != 1) argerr(invarg,"-resize");
  175.         if(sscanf(*++argv,"%d",&opt.res_hgt) != 1) argerr(invarg,"-resize");
  176.         opt.do_resize = 1;
  177.         continue;
  178.         }
  179.         if(strmatch(ap,"-sh")) {
  180.         opt.do_show = 1;
  181.         continue;
  182.         }
  183.         if(strmatch(ap,"-v")) {
  184.         opt.verbose = 1;
  185.         continue;
  186.         }
  187.         argerr("invalid argument: \"%s\"",ap);
  188.     }
  189.     checkoptions();
  190.     if(inputno == 0) argerr("no input file(s) specified");
  191.     qsort(inputs,inputno,sizeof(char *),compareargs);
  192.     if(opt.verbose) printf("%s: LIBGRX font conversion program\n",progname);
  193.     processfonts(inputno,inputs);
  194.     exit(0);
  195. }
  196.  
  197.